﻿using B.S.BsicData.Api.Read.Application.Command;
using B.S.BsicData.Domain;
using B.S.BsicData.ErrorCode.Entity;
using B.S.BsicData.Infartrans;
using MediatR;

namespace B.S.BsicData.Api.Read.Application.CommandHandler
{
    public class QueryPhoneCommandHandler : IRequestHandler<QueryPhoneCommand, ApiPaging<UserModeles>>
    {
        private readonly IBaseReository<UserModeles> userRepo;

        public QueryPhoneCommandHandler(IBaseReository<UserModeles> userRepo)
        {
            this.userRepo = userRepo;
        }

        public async Task<ApiPaging<UserModeles>> Handle(QueryPhoneCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<UserModeles> result = new ApiPaging<UserModeles>();
            var model = userRepo.GetAll().Where(p=>p.UserID==request.UserID).FirstOrDefault();
            if (model!=null)
            {
                result.Code = ApiENums.成功;
                result.Message = "成功";
                result.Data = model;
            }
            else
            {
                result.Code = ApiENums.失败;
                result.Message = "失败";
                result.Data = model;
            }
            return await Task.FromResult(result);
        }
    }
}
